﻿﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>件号单元关联维护</title>
  <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
  <style>
    .inline-block {
      display: inline-block;
    }

    .divLabel {
      margin-bottom: 5px;
    }

    /* 重写下拉框样式 */
    .select {
      width: 200px;
    }

    .combobox-item {
      height: 32px;
    }

    /* 重写日期框样式 */
    .datebox {
      height: 24px !important;
      line-height: 24px !important;
    }

    /* 重写文本框样式 */
    #queryZone .textbox-text,
    #dialogQueryZone .textbox-text,
    #processZone .textbox-text {
      line-height: 22px !important;
      height: 22px !important;
    }

    .l-btn-custom {
      height: 24px !important;
    }

    #btnproductContentClear .l-btn-icon-left,
    #btnworkflowContentClear .l-btn-icon-left {
      margin-top: -1px !important;
    }
  </style>
</head>

<body>
  <div class="panelSection" id="queryZone">
    <div class="easyui-panel " title="查询区域" style="padding:3px 3px 5px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div class="inline-block">
        <div class="divLabel">分厂:</div>
        <select id='ddlFactory' data-options='editable:true' class='easyui-combobox select'
          style="width:160px;"></select>
      </div>

      <div class="inline-block">
        <div class="divLabel">中心:</div>
        <select id='ddlWorkcenter' data-options='editable:true' class='easyui-combobox select'
          style="width:160px;"></select>
      </div>

      <div class="inline-block">
        <div class="divLabel">单元:</div>
        <select id='ddlTeam' data-options='editable:true' class='easyui-combobox select' style="width:160px;"></select>
      </div>

      <div class="inline-block">
        <div class="divLabel">零件号:</div>
        <input id="txtProductname" class="easyui-textbox" style="width:140px;" />
      </div>

      <div class="inline-block">
        <div class="divLabel">创建人:</div>
        <input id="txtCreateEmp" class="easyui-textbox" style="width:140px;" />
      </div>

      <div class="inline-block">
        <div class="divLabel">状态:</div>
        <select id='ddlStatus' value="请选择" data-options='editable:false' class='easyui-combobox select'
          style="width:100px;">
          <option value="请选择">请选择</option>
          <option value="0">启用</option>
          <option value="1">停用</option>
        </select>
      </div>

      <button id="btnSearch" class="easyui-linkbutton" data-options="">查 询</button>
      <button id="btnReset" class="easyui-linkbutton" data-options="">重 置</button>
      <button id="btnExport" class="easyui-linkbutton" data-options="">导 出</button>
    </div>
  </div>

  <div class="panelSection" id="dataGridZone">
    <div class="easyui-panel " title="查询结果" style="padding: 3px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div style="background: #fff; margin: 3px 0px 3px 3px">
        <table id="tbGrid" class="easyui-datagrid" style="height: 350px;" data-options="rownumbers:true">
        </table>
        <div id="pp" style="float: right" class="easyui-pagination" data-options="
                      layout:['list','first','prev','next','last','manual','info'],
                        total: 0,
                        showPageList: true,
                        showPageInfo: false,
                        showRefresh: false,
                        pageList:[10,20,50,100,200],
                        afterPageText:'共&nbsp{pages}&nbsp页'">
        </div>
      </div>
    </div>
  </div>

  <div class="panelSection">
    <div class="easyui-panel " title="操作区域" style="padding:3px 3px 5px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div class="inline-block">
        <div class="divLabel">零件号:</div>
        <input id="txtProductname2" class="easyui-textbox" style="width:160px;" />
      </div>

      <!-- <div class="inline-block">
        <div class="divLabel">零件号:</div>
        <div id="productContent" style="width: 900px;">
        </div>
      </div> -->



      <div class="inline-block">
        <div class="divLabel">中心:</div>
        <select id='ddlWorkcenter2' data-options='editable:true' class='easyui-combobox select'
          style="width:160px;"></select>
      </div>

      <div class="inline-block">
        <div class="divLabel">单元:</div>
        <select id='ddlTeam2' data-options='editable:true' class='easyui-combobox select' style="width:160px;"></select>
      </div>
    </div>
  </div>

  <div style="margin:5px;">
    <button id="btnAdd" class="easyui-linkbutton" data-options="">添加</button>
    <button id="btnChangeTeam" class="easyui-linkbutton" data-options="">修改单元</button>
    <button id="btnInUse" class="easyui-linkbutton" data-options="">启用</button>
    <button id="btnUnUse" class="easyui-linkbutton" data-options="">停用</button>
  </div>
</body>

</html>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/array.pollyfill.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ProductLinkageWorkflow2.js" type="text/javascript"></script>
<script type="text/javascript">
  /**
   * 创建人：zhunan
   * 日期：2024.12.10
   * 描述：件号单元关联维护
  */
  var page = {
    pagetotal: 0,
    pageNumber: 1,
    pageSize: 10,
    mainUrl: getRootPath() + "/Ashx/ProductTeamInfoMaintPageHandler.ashx", //本页面后台路径
    //初始化页面
    init: function () {
      page.bind();
      page.initData(); //初始化页面数据
      $("#ddlStatus").combobox({ value: '请选择' });
    },
    // 页面事件绑定
    bind: function () {
      // 重点批次进度表格
      $("#tbGrid").datagrid({
        columns: [[
          { field: 'ck', title: '选择', checkbox: true },
          { field: 'id', title: 'id', width: 100, hidden: true },
          { field: 'teamid', title: 'teamid', width: 100, hidden: true },
          { field: 'workcenterid', title: 'workcenterid', width: 100, hidden: true },
          { field: 'productname', title: '零件号', width: 100 },
          { field: 'description', title: '零件名称', width: 160 },
          { field: 'factoryname', title: '分厂', width: 100 },
          { field: 'workcentername', title: '中心', width: 100 },
          { field: 'teamname', title: '单元', width: 100 },
          { field: 'isuse', title: '状态', width: 80 },
          {
            field: 'createdate', title: '创建时间', width: 190,
            formatter: function (value) {
              if (value) {
                return value.replace('T', ' ');
              } else {
                return "";
              }
            }
          },
          { field: 'createemp', title: '创建人', width: 100 },
          {
            field: 'lastchangedate', title: '更新时间', width: 190,
            formatter: function (value) {
              if (value) {
                return value.replace('T', ' ');
              } else {
                return "";
              }
            }
          },
          { field: 'lastchangeemp', title: '更新人', width: 140 }
        ]],
        onLoadSuccess: function (data) {
          $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
            total: page.pagetotal,
            pageSize: page.pageSize,
            pageNumber: page.pageNumber
          });
          customizedEasyuiPagination('pp'); //定制化分页
        },
        onCheck: function (rowIndex, rowData) {
        }
      });

      //分页事件
      $('#pp').pagination({
        onSelectPage: function (pageNumber, pageSize) {
          customizedEasyuiPagination('pp'); //定制化分页
          page.pageSize = pageSize;
          page.pageNumber = pageNumber;
          page.search();
        }
      });

      // 查询按钮
      $("#btnSearch").on("click", function () {
        page.pageNumber = 1;
        page.search();
      });

      // 重置
      $("#btnReset").on('click', function () {
        page.resetData();
      });

      // 导出
      $("#btnExport").on('click', function () {
        page.exportExcel();
      });

      // 添加
      $('#btnAdd').on('click', function () {
        var productname = $("#txtProductname2").textbox('getValue');
        var teamid = $('#ddlTeam2').combobox('getValue');
        if (!productname) {
          return displayMessage("请输入零件号", false);
        }
        if (!teamid) {
          return displayMessage("请选择单元", false);
        }
        $.messager.confirm('确认', '你确认要添加吗?', function (r) {
          if (!r) { return; }
          $.ajax({
            type: "post",
            url: page.mainUrl + "?actions=addData",
            data: {
              action: "addData",
              productname: productname,
              teamid: teamid
            },
            cashe: false,
            dataType: 'json',
            success: function (res) {
              if (res.Result) {
                displayMessage('添加成功', true);
                $("#txtProductname2").textbox('clear');
                $("#ddlTeam2").textbox('clear');
                $('#ddlWorkcenter2').combobox('clear');
                $('#tbGrid').datagrid('loadData', []);
              } else {
                displayMessage(res.Message, false);
              }
            }
          })
        });
      });

      // 修改单元
      $('#btnChangeTeam').on('click', function () {
        var selectData = $("#tbGrid").datagrid('getChecked');
        if (selectData.length === 0) {
          displayMessage("请勾选需要修改的记录！", false);
          return;
        }

        var teamid = $('#ddlTeam2').combobox('getValue');
        var teamname = $('#ddlTeam2').combobox('getText');
        if (!teamid) {
          return displayMessage("请选择单元", false);
        }

        $.messager.confirm('确认', '你确认要将所选件号单元变更为【' + teamname + '】吗?', function (r) {
          if (!r) { return; }
          $.ajax({
            type: "post",
            url: page.mainUrl + "?actions=changeTeam",
            data: {
              action: "changeTeam",
              teamid: teamid,
              postData: JSON.stringify(selectData),
            },
            cashe: false,
            dataType: 'json',
            success: function (res) {
              if (res.Result) {
                displayMessage('单元修改成功', true);
                $("#txtProductname2").textbox('clear');
                $("#ddlTeam2").textbox('clear');
                $('#ddlWorkcenter2').combobox('clear');
                $('#tbGrid').datagrid('loadData', []);
              } else {
                displayMessage(res.Message, false);
              }
            }
          })
        });
      });

      // 启用
      $('#btnInUse').on('click', function () {
        page.changeIsuse('0');
      });

      // 停用
      $('#btnUnUse').on('click', function () {
        page.changeIsuse('1');
      });

    },
    // 初始化页面
    initData: function () {
      page.getFactory();
    },
    // 查询
    search: function () {
      var formData = {
        action: "getData",
        pageSize: page.pageSize,
        pageNumber: page.pageNumber,
        factoryid: $('#ddlFactory').combobox('getValue'),//分厂
        workcenterid: $('#ddlWorkcenter').combobox('getValue'),//中心
        teamid: $('#ddlTeam').combobox('getValue'),//单元
        productname: $("#txtProductname").textbox('getValue'),//零件号
        createEmp: $("#txtCreateEmp").textbox('getValue'),//创建人
        status: $('#ddlStatus').combobox('getValue')//状态
      };

      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=getData",
        data: formData,
        cashe: false,
        async: true,
        beforeSend: function () {
          $('#tbGrid').datagrid('loading');
          $(this).attr("disabled", "disabled"); //禁用按钮
        },
        success: function (data) {
          $('#tbGrid').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          var result = JSON.parse(data);
          if (result.Result) {
            //给分页对象赋值
            page.pagetotal = result.RowCount;
            $('#tbGrid').datagrid('loadData', { total: result.RowCount, rows: result.DBTable });
          } else {
            displayMessage(result.Message, false);
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $('#tbGrid').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          alert(XMLHttpRequest.responseText);
        }
      });
    },
    // 启用、停用
    changeIsuse: function (type) {
      var isuse = type || '0';
      var status = isuse === '1' ? '停用' : '启用';

      var selectData = $("#tbGrid").datagrid('getChecked');
      if (selectData.length === 0) {
        displayMessage("请勾选需要修改的记录！", false);
        return;
      }
      $.messager.confirm('确认', '你确认要将所选数据状态更改为【' + status + '】吗?', function (r) {
        if (!r) { return; }
        $.ajax({
          type: "post",
          url: page.mainUrl + "?actions=changeIsuse",
          data: {
            action: "changeIsuse",
            isuse: isuse,
            postData: JSON.stringify(selectData),
          },
          cashe: false,
          dataType: 'json',
          success: function (res) {
            if (res.Result) {
              displayMessage(status + '成功', true);
              $("#txtProductname2").textbox('clear');
              $("#ddlTeam2").textbox('clear');
              $('#ddlWorkcenter2').combobox('clear');
              $('#tbGrid').datagrid('loadData', []);
            } else {
              displayMessage(res.Message, false);
            }
          }
        })
      });
    },
    // 获取分厂列表
    getFactory: function () {
      $.ajax({
        type: "post",
        url: getRootPath() + "/Ashx/ApsHandler/EmployeeMaintPage.ashx?actions=getFactory",
        data: { action: "GetFactory" },
        cashe: false,
        dataType: 'json',
        success: function (res) {
          if (res.Result) {
            // 绑定弹出框分厂下拉框
            $("#ddlFactory").combobox({
              valueField: 'factoryid',
              textField: 'factoryname',
              panelHeight: 200,
              data: res.DBTable,
              onSelect: function (record) {
                if (record.factoryid) {
                  page.getWorkcenter(record.factoryid);
                  $('#ddlTeam').combobox('clear');
                  $('#ddlTeam').combobox('loadData', []);
                }
              }
            });

            $.ajax({
              type: "post",
              url: page.mainUrl + "?actions=getUserInfo",
              data: { action: "getUserInfo" },
              cashe: false,
              dataType: 'json',
              success: function (res) {
                if (res.Result) {
                  if (res.ReturnData.FactoryID) {
                    $("#ddlFactory").combobox('select', res.ReturnData.FactoryID);
                    $('#ddlFactory').combobox('disable');
                    page.getWorkcenter(res.ReturnData.FactoryID);
                  }
                } else {
                  displayMessage(res.Message, false);
                }
              }
            });
          }
        }
      });
    },
    // 查询中心
    getWorkcenter: function (factoryid) {
      $.ajax({
        type: "post",
        url: page.mainUrl + "?actions=getWorkcenter",
        data: { action: "getWorkcenter", factoryid: factoryid },
        cashe: false,
        dataType: 'json',
        success: function (res) {
          if (res.Result) {
            $("#ddlWorkcenter").combobox({
              valueField: 'workcenterid',
              textField: 'workcentername',
              panelHeight: 200,
              data: res.DBTable,
              onSelect: function (record) {
                if (record.workcenterid) {
                  page.getTeam(record.workcenterid, 'ddlTeam');
                }
              }
            });

            $("#ddlWorkcenter2").combobox({
              valueField: 'workcenterid',
              textField: 'workcentername',
              panelHeight: 200,
              data: res.DBTable,
              onSelect: function (record) {
                if (record.workcenterid) {
                  page.getTeam(record.workcenterid, 'ddlTeam2');
                }
              }
            });
          }
        }
      });
    },
    // 查询单元（班组）
    getTeam: function (workcenterid, domid) {
      $.ajax({
        type: "post",
        url: page.mainUrl + "?actions=getTeam",
        data: { action: "getTeam", workcenterid: workcenterid },
        cashe: false,
        dataType: 'json',
        success: function (res) {
          if (res.Result) {
            $("#" + domid).combobox({
              valueField: 'teamid',
              textField: 'teamname',
              panelHeight: 200,
              data: res.DBTable
            });
          }
        }
      });
    },
    // 重置
    resetData: function () {
      $("#tbGrid").datagrid('loadData', { total: 0, rows: [] });
      page.pageNumber = 1;
      page.pageSize = 10;

      $('#pp').pagination('refresh', { // 改变选项并刷新分页栏信息
        total: 0,
        pageNumber: 1,
        pageSize: 10
      });

      $("#txtProductname").textbox('clear');
      $("#txtCreateEmp").textbox('clear');
      $('#ddlWorkcenter').combobox('clear');
      $('#ddlTeam').combobox('clear');
      $('#ddlTeam').combobox('loadData', []);
      $("#ddlStatus").combobox('select', '请选择');
      $("#txtProductname2").textbox('clear');
      $("#ddlTeam2").textbox('clear');
      $('#ddlWorkcenter2').combobox('clear');
    },
    // 导出
    exportExcel: function () {
      var formData = {
        action: "exportExcel",
        factoryid: $('#ddlFactory').combobox('getValue'),//分厂
        workcenterid: $('#ddlWorkcenter').combobox('getValue'),//中心
        teamid: $('#ddlTeam').combobox('getValue'),//单元
        productname: $("#txtProductname").textbox('getValue'),//零件号
        createEmp: $("#txtCreateEmp").textbox('getValue'),//创建人
        status: $('#ddlStatus').combobox('getValue')//状态
      };

      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=exportExcel",
        data: formData,
        cashe: false,
        async: true,
        beforeSend: function () {
          $('#tbGrid').datagrid('loading');
          $(this).attr("disabled", "disabled"); //禁用按钮
        },
        success: function (data) {
          $('#tbGrid').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          var result = JSON.parse(data);
          if (result.Result) {
            //通过创建a标签实现
            var link = document.createElement("a");
            link.href = result.ReturnData.url;
            //对下载的文件命名
            link.download = result.ReturnData.filename;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
          } else {
            displayMessage(result.Message, false);
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $('#tbGrid').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          alert(XMLHttpRequest.responseText);
        }
      });

    }
  };

  $(function () {
    page.init();
  });
</script>